<template>
	<view class="head">
		<image :src="head['avatar_url'] || ''" @error="imgError"></image>
		<text>{{head['loginname'] || '--'}}</text>
		<text>积分：{{head['score'] || '--'}}</text>
		<text>C龄：{{fmTime}}</text>
	</view>
</template>

<script>
	export default {
		props: ['head'],
		computed: {
			fmTime (){
				if(!this.head['create_at']){
					return '--'
				}
			    const now = (new Date()).valueOf();
			    const pre = (new Date(this.head['create_at'])).valueOf();
			    const offset = now - pre;
			    if (offset < 3600 * 24 * 30 * 1000) return `${Math.floor(offset / (3600 * 24 * 1000))}天`;
			    else if (offset < 3600 * 24 * 30 * 12 * 1000) return `${Math.floor(offset / (3600 * 24 * 30 * 1000))}个月`;
			    else return `${(offset / (3600 * 24 * 30 * 1000 * 12)).toFixed(1)}年`;
			}
		},
		methods: {
			imgError (e){
				console.log(e)
			}
		}
	}
</script>

<style lang="scss">
	.head{
		padding: 10px 0;
		text-align: center;
		border-bottom: 1px solid #eee;
		background-color: #fff;
		image{
			width: 200rpx;
			height: 200rpx;
			border-radius: 100%;
			border: 1px solid #ccc;
		}
		text{
			display: block;
			line-height: 1.8;
			color: $baseColor;
			font-size: 14px;
		}
	}
</style>
